import GameManager from "../GameManager";
import WTool from "../WTool";
import { ZTool } from "../ZTool";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Earth extends cc.Component {
    private Tween: cc.Tween;
    onLoad() {
        this.Init();
    }

    start() {
        this.Tween = WTool.Tween_AngleForever(this.node, 120, -360, () => {
            this.node.angle = 0;
        })
    }

    /**初始化草垛 */
    Init() {
        for (let i = 0; i < 40; i++) {
            GameManager.Instance.LoadPrefab("Root", (pre) => {
                let root = cc.instantiate(pre);
                root.setParent(this.node);
                root.angle = i * 9;
                GameManager.Instance.LoadPrefab("Build" + ZTool.GetRandomIntWithMax(1, 5), (pre) => {
                    let build = cc.instantiate(pre);
                    build.setParent(root);
                })
            })
        }
    }

    //结束旋转
    Stop() {
        this.Tween.stop();
    }
    // update (dt) {}
}
